#ifndef WORKBENCH_H
#define WORKBENCH_H

#include <QApplication>
#include "uiloader.h"
#include "QScriptEngine"
#include "abstractstorage.h"

class ScriptManager;
class DatabaseManager;
class Settings;
class DataTreeHelper;
class QWidget;
class Communicator;

// Core application logic
class Workbench : public QObject
{
    Q_OBJECT
public:    
    ~Workbench();
    static Workbench *instance();
    void loadProject(const QString& projectFile = QString());

    // ************* Script accessible functions ************
    Q_INVOKABLE QWidget* loadForm(int formIndex);
    Q_INVOKABLE Settings* settings() { return m_settings; }
    Q_INVOKABLE void settingsDialog();
    Q_INVOKABLE QVariant inputDialog(const QString& label = QString(), const QString& value = QString(), QWidget* parent = 0);
    Q_INVOKABLE QVariant dateDialog();
    // *******************************************************

    AbstractStorage* project() { return &m_project; }
    QString projectFolder() { return m_projectFolder; }

private:
    bool readProjectFile(QString xmlname);
    void loadMainScript(const QString &scriptFile);
    void loadOtherScripts();

    UiLoader loader;
    ScriptManager *m_scriptManager;
    DatabaseManager *m_databaseManager;
    AbstractStorage m_project;    

    QString m_projectFile;
    QString m_projectFolder;    

    Settings *m_settings;

    static Workbench *m_instance;

    Workbench();
};

#endif // WORKBENCH_H
